/*********************************************************************************
  *Copyright (c)    2021   xldeng
  *FileName:        3.cpp.c
  *Author:          xldeng
  *Version:         1.0
  *Date:            2021/2/9 14:54
  *Description:     
  *Others:          
  *Function List:   
     1.…………
  *History:  
     1.Date:
       Author:
       Modification:
**********************************************************************************/
/*
 * 给定一个字符串，请你找出其中不含有重复字符的 最长子串 的长度
 */
#include "../header.h"

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_map<char, int> window;
        int left = 0, right = 0, ans = 0;
        while (right < s.size()) {
            char c = s[right++];
            window[c]++;
            while (window[c] > 1) {
                char d = s[left++];
                window[d]--;
            }
            ans = max(ans, right - left);
        }
        return ans;
    }
};